/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.service;

import br.com.foxline.clinicplus.entity.Operator;
import br.com.foxline.clinicplus.entity.Procedure;
import br.com.foxline.clinicplus.entity.ValueProcedure;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author roniere
 */
@Stateless
public class ValueProcedureService extends GenericService<ValueProcedure> {

    public ValueProcedureService() {
        super(ValueProcedure.class);
    }

    public Procedure getProcedureForId(Long id) {

        String sql = "select p from Procedure p JOIN p.valueProcedure v JOIN v.operator o "
                + " WHERE v.id = :id and p.active = true ";

        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", id);
        
        return (Procedure) query.getSingleResult();
    }
}
